/**
 * 
 */

function handleAjax(data) {
	var status = data.status;

	switch (status) {
		case "begin" :
			// This is invoked right before ajax request is sent.
			break;

		case "complete" :
			// This is invoked right after ajax response is returned.
			break;

		case "success" :
			// This is invoked right after successful processing of ajax
			// response and update of HTML DOM.
			focusValidationFailures();
			break;
	}
}

function focusValidationFailures() {
	// find parent - remove has-error class
	// find next has-error
	// get tab-pane id and show
	// focus to next has-error
	focusFirstElement();

	// do the same if an input was made
	$('.form-control').change(function() {
		focusFirstElement();
		}
	);
	
	function focusFirstElement(){
		invalid_controls = document.getElementsByClassName('has-error');
		if (typeof invalid_controls !== 'undefined' && invalid_controls.length > 0) {
			$('#tabs a[href$="#' + jQuery(invalid_controls[0]).closest(".tab-pane").attr('id') + '"]').tab('show');
			jQuery(invalid_controls[0].getElementsByTagName("input")[0]).focus();
		}
	}
}



// jQuery(document).ready(function() {
// jQuery('#editUserForm').validate({
// ignore: ".ignore",
// invalidHandler: function(e, validator){
// if(validator.errorList.length)
// $('#tabs a[href="#' +
// jQuery(validator.errorList[0].element).closest(".tab-pane").attr('id') +
// '"]').tab('show')
// }
// });
//    
// jQuery('.userEditSubmit').click(function(evt) {
// evt.preventDefault();
//        
// jQuery('#editUserForm').submit()
//        
// });
// });
